#pragma once

#include "../util/que.h"

class CMsg;
struct ProcessorAffinity;

class CTask
{
typedef std::list<DWORD>	DWLIST;
public:
	CTask();
	virtual ~CTask();

protected:	
	IQue<CMsg*>*		m_pMsgQue;
	CQueMT<CMsg*>*		m_pMsgQueMT;
		
	DWLIST				m_ThreadIDs;
	CThreadManager*		m_pThreadMgr;
	THREADCONF			m_TC;
	CCriticalSectionBS	m_CS;
	
	DWORD				m_nThreadCount;
public:
	BOOL	Create(CThreadManager* pThreadMgr, CRuntime* pRT_ServiceObj, ULONG_PTR Data);
	BOOL	WaitForExitThreads();
	BOOL	Suspend();
	BOOL	Resume();
	size_t	GetQueuedMsgCount() { _ASSERT(m_pMsgQue != NULL); return m_pMsgQue->GetSize(); }
//	BOOL	StartJob(long ThreadNumToSpawn, long nPriority = THREAD_PRIORITY_NORMAL, DWORD dwStackSize = 0, DWORD dwFlags = 0, ProcessorAffinity* pPA = NULL);
	BOOL	StartJob(long ThreadNumToSpawn, long nPriority = THREAD_PRIORITY_NORMAL, DWORD dwStackSize = (1024 * 1024 * 2), DWORD dwFlags = 0, ProcessorAffinity* pPA = NULL);
	BOOL	EnqueMsg(CMsg* pMsg) { return m_pMsgQue->Enque(pMsg); }
	BOOL	DequeMsg(CQueMT<CMsg*>::Items& msgs, DWORD dwTimeout);
	BOOL	DequeMsg(CMsg** ppMsg, DWORD dwTimeout,BOOL bForCleanup = FALSE) { return m_pMsgQue->Deque(ppMsg, dwTimeout); }
	BOOL	IsQueueEmpty(){ return m_pMsgQue->IsEmpty(); }
	BOOL	DeactivateMsgQue() { return m_pMsgQue->Deactivate(); }
	CServiceObject*	GetServiceObject() { SCOPED_LOCK_SINGLE(&m_CS); return m_TC.pServiceObject; }
	DWORD	GetThreadCount(){ return m_nThreadCount;}
};
